from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-28 14:05:06.468860
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 28, Jul, 2022
Time: 14:05:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.9522
Nobs: 731.000 HQIC: -50.2996
Log likelihood: 9219.07 FPE: 1.14918e-22
AIC: -50.5178 Det(Omega_mle): 1.01690e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299318 0.056535 5.294 0.000
L1.Burgenland 0.107739 0.037128 2.902 0.004
L1.Kärnten -0.106958 0.019680 -5.435 0.000
L1.Niederösterreich 0.207946 0.077703 2.676 0.007
L1.Oberösterreich 0.107016 0.075776 1.412 0.158
L1.Salzburg 0.254026 0.039703 6.398 0.000
L1.Steiermark 0.042418 0.051793 0.819 0.413
L1.Tirol 0.108794 0.042010 2.590 0.010
L1.Vorarlberg -0.062713 0.036217 -1.732 0.083
L1.Wien 0.047539 0.067023 0.709 0.478
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054718 0.118161 0.463 0.643
L1.Burgenland -0.031935 0.077599 -0.412 0.681
L1.Kärnten 0.047068 0.041133 1.144 0.253
L1.Niederösterreich -0.177989 0.162403 -1.096 0.273
L1.Oberösterreich 0.409408 0.158375 2.585 0.010
L1.Salzburg 0.288391 0.082982 3.475 0.001
L1.Steiermark 0.108382 0.108251 1.001 0.317
L1.Tirol 0.311366 0.087804 3.546 0.000
L1.Vorarlberg 0.026036 0.075696 0.344 0.731
L1.Wien -0.028212 0.140082 -0.201 0.840
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188282 0.028939 6.506 0.000
L1.Burgenland 0.090335 0.019005 4.753 0.000
L1.Kärnten -0.008903 0.010074 -0.884 0.377
L1.Niederösterreich 0.261446 0.039774 6.573 0.000
L1.Oberösterreich 0.138325 0.038787 3.566 0.000
L1.Salzburg 0.046092 0.020323 2.268 0.023
L1.Steiermark 0.020939 0.026511 0.790 0.430
L1.Tirol 0.093159 0.021504 4.332 0.000
L1.Vorarlberg 0.056401 0.018539 3.042 0.002
L1.Wien 0.115053 0.034307 3.354 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110703 0.029447 3.759 0.000
L1.Burgenland 0.045740 0.019339 2.365 0.018
L1.Kärnten -0.013998 0.010251 -1.365 0.172
L1.Niederösterreich 0.188390 0.040473 4.655 0.000
L1.Oberösterreich 0.301357 0.039469 7.635 0.000
L1.Salzburg 0.109743 0.020680 5.307 0.000
L1.Steiermark 0.104833 0.026978 3.886 0.000
L1.Tirol 0.105688 0.021882 4.830 0.000
L1.Vorarlberg 0.068288 0.018865 3.620 0.000
L1.Wien -0.021403 0.034910 -0.613 0.540
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128401 0.053662 2.393 0.017
L1.Burgenland -0.049820 0.035241 -1.414 0.157
L1.Kärnten -0.040854 0.018680 -2.187 0.029
L1.Niederösterreich 0.164904 0.073755 2.236 0.025
L1.Oberösterreich 0.140306 0.071925 1.951 0.051
L1.Salzburg 0.289327 0.037686 7.677 0.000
L1.Steiermark 0.037023 0.049161 0.753 0.451
L1.Tirol 0.163277 0.039876 4.095 0.000
L1.Vorarlberg 0.100219 0.034377 2.915 0.004
L1.Wien 0.069369 0.063618 1.090 0.276
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054110 0.042676 1.268 0.205
L1.Burgenland 0.039448 0.028026 1.408 0.159
L1.Kärnten 0.050978 0.014856 3.431 0.001
L1.Niederösterreich 0.217770 0.058655 3.713 0.000
L1.Oberösterreich 0.295990 0.057200 5.175 0.000
L1.Salzburg 0.043792 0.029970 1.461 0.144
L1.Steiermark 0.001238 0.039097 0.032 0.975
L1.Tirol 0.143414 0.031712 4.522 0.000
L1.Vorarlberg 0.072786 0.027339 2.662 0.008
L1.Wien 0.081217 0.050593 1.605 0.108
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173431 0.051010 3.400 0.001
L1.Burgenland -0.002548 0.033500 -0.076 0.939
L1.Kärnten -0.062607 0.017757 -3.526 0.000
L1.Niederösterreich -0.082219 0.070110 -1.173 0.241
L1.Oberösterreich 0.191538 0.068371 2.801 0.005
L1.Salzburg 0.058257 0.035823 1.626 0.104
L1.Steiermark 0.235683 0.046732 5.043 0.000
L1.Tirol 0.498350 0.037905 13.147 0.000
L1.Vorarlberg 0.045696 0.032678 1.398 0.162
L1.Wien -0.053301 0.060474 -0.881 0.378
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168595 0.058655 2.874 0.004
L1.Burgenland -0.007529 0.038520 -0.195 0.845
L1.Kärnten 0.066322 0.020418 3.248 0.001
L1.Niederösterreich 0.204289 0.080617 2.534 0.011
L1.Oberösterreich -0.071302 0.078617 -0.907 0.364
L1.Salzburg 0.207958 0.041192 5.048 0.000
L1.Steiermark 0.123141 0.053736 2.292 0.022
L1.Tirol 0.071377 0.043586 1.638 0.101
L1.Vorarlberg 0.119040 0.037576 3.168 0.002
L1.Wien 0.119987 0.069537 1.726 0.084
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360182 0.033791 10.659 0.000
L1.Burgenland 0.007299 0.022192 0.329 0.742
L1.Kärnten -0.023679 0.011763 -2.013 0.044
L1.Niederösterreich 0.216853 0.046443 4.669 0.000
L1.Oberösterreich 0.198337 0.045291 4.379 0.000
L1.Salzburg 0.043091 0.023731 1.816 0.069
L1.Steiermark -0.013378 0.030957 -0.432 0.666
L1.Tirol 0.104834 0.025110 4.175 0.000
L1.Vorarlberg 0.070803 0.021647 3.271 0.001
L1.Wien 0.037698 0.040060 0.941 0.347
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039853 0.139123 0.191170 0.150938 0.117491 0.103187 0.062618 0.216266
Kärnten 0.039853 1.000000 -0.007033 0.132733 0.039251 0.094370 0.433320 -0.053527 0.097720
Niederösterreich 0.139123 -0.007033 1.000000 0.335026 0.142447 0.294115 0.095443 0.177452 0.314892
Oberösterreich 0.191170 0.132733 0.335026 1.000000 0.228301 0.324790 0.175548 0.164528 0.261350
Salzburg 0.150938 0.039251 0.142447 0.228301 1.000000 0.142332 0.112030 0.144866 0.124680
Steiermark 0.117491 0.094370 0.294115 0.324790 0.142332 1.000000 0.145989 0.137749 0.071396
Tirol 0.103187 0.433320 0.095443 0.175548 0.112030 0.145989 1.000000 0.111658 0.143651
Vorarlberg 0.062618 -0.053527 0.177452 0.164528 0.144866 0.137749 0.111658 1.000000 -0.000646
Wien 0.216266 0.097720 0.314892 0.261350 0.124680 0.071396 0.143651 -0.000646 1.000000